import React, {Fragment} from 'react';
import {Tooltip, Tag, Icon} from 'antd';
import {Link} from 'react-router';
import Utils from "../utils";

module.exports = [
  {
    key: 'id',
    title: 'ID',
    dataType: 'int',
    primary: true,
    showType: 'normal',
    showInTable: true,
    showInForm: false,
    disabled: true,
    width: 80,
    render: (text, record) => text
  },
  {
    key: 'thumb',
    title: '缩略图',
    dataType: 'varchar',
    showType: 'image',
    width: 100,
  },
  {
    key: 'name',
    title: '商品名称',
    width: 150,
    dataType: 'varchar',
    render: (text, record) => {
      const tags = record.$$rawData.tags;
      const tagsElements = [];
      for (let item in tags) {
        tagsElements.push(
          <Tag key={tags[item].id} color={tags[item].color}>{tags[item].title}</Tag>
        );
      }

      return (
        <Fragment>
          <p>{text}</p>
          {tagsElements}
        </Fragment>
      );
    }
  },
  {
    key: 'goodsNo',
    title: '商品编号',
    dataType: 'varchar',
    width: 90
  },
  {
    key: 'categoryId',
    title: '商品分类',
    dataType: 'varchar',
    showType: 'select',
    width: 90,
    options: [],
    render(text, record) {
      if (!text) {
        return '';
      }
      return text.replace(/[├└]─ /, '');
    }
    //options: [{key: 1, value: "傻逼"}, {key: 15, value: "你妹啊"}]
  },
  {
    key: 'sellingPrice',
    title: '销售价格',
    width: 120,
    dataType: 'int',
    render: (text) => Utils.formatMoney(text / 100),
    sorter: (a, b) => a.sellingPrice - b.sellingPrice
  },
  {
    key: 'marketPrice',
    title: '市场价格',
    width: 120,
    dataType: 'int',
    render: (text) => Utils.formatMoney(text / 100),
    sorter: (a, b) => a.marketPrice - b.marketPrice
  },
  {
    key: 'stock',
    title: '库存',
    width: 90,
    showInForm: false,
    render: (text, row) => row.$$rawData.isInfiniteStock ? '无限' : text,
    sorter: (a, b) => a.stock - b.stock
  },
  {
    key: 'tagsId',
    title: '商品标签',
    dataType: 'varchar',
    showType: 'select',
    options: [],
    showInTable: false
  },
  {
    key: 'goodsSkus',
    title: 'SKU',
    showInTable: false,
    showInForm: false
  },
  {
    key: 'other',
    title: '操作',
    width: 90,
    showInForm: false,
    render: (text, record) => {
      return <Link to={`/goodsManage/GoodsDetails/` + record.id}>
        <Tooltip placement="top" title='查看商品信息'>
          <Icon type="form"/>
        </Tooltip>
      </Link>;
    }
  },
];